package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Menuinventory;
import com.restaurant.service.MenuinventoryService;

public class MenuinventoryServiceImpl implements MenuinventoryService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menuinventory addOrModify( Menuinventory objMenuinventory ) {
       return ( Menuinventory ) hibernateTemplate.merge( objMenuinventory );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menuinventory deleteRecord( Menuinventory objMenuinventory ) {
       hibernateTemplate.delete( objMenuinventory );
       return objMenuinventory;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menuinventory modifyRecord( Menuinventory objMenuinventory ) {
       return ( Menuinventory ) hibernateTemplate.merge( objMenuinventory );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Menuinventory> loadAll() {
       return (List<Menuinventory>)hibernateTemplate.findByNamedQuery( "Menuinventory.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menuinventory loadByPrimaryKey( Long primaryKey ) {
       return (Menuinventory) hibernateTemplate.get( Menuinventory.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menuinventory deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Menuinventory> loadByHql(String query) {
       return ( List<Menuinventory> ) hibernateTemplate.find( query );
   }
}